package com.yikaiye.android.yikaiye.ui.activity.service.viewmodel;

import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
import com.yikaiye.android.yikaiye.base.BaseViewModel;
import com.yikaiye.android.yikaiye.config.Constant;
import com.yikaiye.android.yikaiye.di.retrofit.BaseModel;
import com.yikaiye.android.yikaiye.di.retrofit.BaseNetCallback;
import com.yikaiye.android.yikaiye.model.ServiceDetailsModel;

import java.util.HashMap;
import java.util.Map;

public class ServiceDetailsViewModel extends BaseViewModel {
    public MutableLiveData<ServiceDetailsModel> detailsModelMutableLiveData = new MutableLiveData<>();

    /**
     * 获取服务详情
     *
     * @param id 服务id
     * @param messageId 消息id
     */
    public void getServiceDetails(String id, String messageId) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("messageId", messageId);
        addSubscribe(mRetrofitHelper.getServiceDetails(new Gson().toJson(map)).subscribeWith(new BaseNetCallback<ServiceDetailsModel>() {

            @Override
            public void onSuccess(BaseModel<ServiceDetailsModel> baseModel) {
                if (Constant.SUCCESS == baseModel.getCode() && baseModel.getData() != null) {
                    detailsModelMutableLiveData.setValue(baseModel.getData());
                } else {
                    mErrorData.setValue(baseModel.getMsg());
                }
            }

            @Override
            public void onError(String message) {
                super.onError(message);
                mErrorData.setValue(message);
            }
        }));
    }
}
